package com.blandware.atleap.webapp.form.core;

import com.blandware.atleap.webapp.form.BaseForm;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Form bean that serves to update application resource.
 * Used to collect values for all locales associated with single key</p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/08/03 10:08:05 $
 * @struts.form name="applicationResourceForm"
 */
public class ApplicationResourceForm extends BaseForm implements Serializable {

	/**
	 * Key of application resource
	 */
	protected String key;

	/**
	 * Map of values associated with key
	 */
	protected Map valueMap = new HashMap();

	/**
	 * Map of versions to enable for optimistic locking feature
	 */
	protected Map versionMap = new HashMap();


	/**
	 * Returns key of application resource
	 *
	 * @return Key of application resource
	 */
	public String getKey() {
		return key;
	}

	/**
	 * Sets key of application resource
	 *
	 * @param key Key of application resource
	 */
	public void setKey(String key) {
		this.key = key;
	}

	/**
	 * Returns map of values associated with key
	 *
	 * @return Map of values associated with key
	 */
	public Map getValueMap() {
		return this.valueMap;
	}

	/**
	 * Sets map of values associated with key
	 *
	 * @param valueMap Map of values associated with key
	 */
	public void setValueMap(Map valueMap) {
		this.valueMap = valueMap;
	}

	/**
	 * Returns value associated with specified locale identifier
	 *
	 * @param localeIdentifier Identifier of locale to return value associated with
	 * @return Value associated with locale with specified identifier
	 */
	public Object getValue(String localeIdentifier) {
		return valueMap.get(localeIdentifier);
	}

	/**
	 * Sets value for specified locale identifier
	 *
	 * @param localeIdentifier Locale identifier to associate value with
	 * @param value            Value to associate with given locale identifier
	 */
	public void setValue(String localeIdentifier, Object value) {
		valueMap.put(localeIdentifier, value);
	}

	/**
	 * Returns map of versions
	 *
	 * @return Map of versions
	 */
	public Map getVersionMap() {
		return this.versionMap;
	}

	/**
	 * Sets map of versions
	 *
	 * @param versionMap Map of versions to set
	 */
	public void setVersionMap(Map versionMap) {
		this.versionMap = versionMap;
	}

	/**
	 * Returns version associated with given locale identifier
	 *
	 * @param localeIdentifier Locale identifier to get version associated with
	 * @return Version associated with given locale identifier
	 */
	public Object getVersion(String localeIdentifier) {
		return versionMap.get(localeIdentifier);
	}

	/**
	 * Associates version with locale identifier
	 *
	 * @param localeIdentifier Locale identifier to associate version with
	 * @param version          Version to associate with given locale identifier
	 */
	public void setVersion(String localeIdentifier, Object version) {
		versionMap.put(localeIdentifier, version);
	}

	/**
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {

		// reset all mapped properties to default values
		this.valueMap = new HashMap();
		this.versionMap = new HashMap();

	}
}
